--- import Layout from '../layouts/Layout.astro'; import mockServerScript from '../assets/js/mock-server.js?raw'; import Sidebar from '../components/Sidebar.astro'; import TableOfContents from '../components/TableOfContents.astro'; import Breadcrumbs from '../components/Breadcrumbs.astro'; import PageHeader from '../components/PageHeader.astro'; import Pagination from '../components/Pagination.astro'; import FinderLink from '../components/FinderLink.astro'; import { getFolder, render, COLLECTIONS } from '../lib/content'; import { buildDocsSidebar } from '../lib/docs-sidebar'; export async function getStaticPaths() { const paths = []; for (const collection of COLLECTIONS) { const isHome = collection === 'home'; const folder = await getFolder(collection); paths.push({ params: { slug: isHome ? undefined : collection }, props: { folder, collection } }); folder.allFiles.forEach((file) => { paths.push({ params: { slug: isHome ? file.slug : `${collection}/${file.slug}` }, props: { file, folder, collection } }); }); // Reference subfolders are listed inline on /reference, no separate pages if (collection !== 'reference') { folder.folders.forEach((subfolder) => { paths.push({ params: { slug: `${collection}/${subfolder.slug}` }, props: { subfolder, folder, collection } }); }); } } return paths; } const { file, subfolder, folder, collection } = Astro.props; const isCollectionRootPage = !file && !subfolder; const isSubfolderIndexPage = !!subfolder; const isHomePage = isCollectionRootPage && collection === 'home'; const page = isCollectionRootPage ? folder! : isSubfolderIndexPage ? subfolder! : file; const {Content} = await render(page); const {title, description, keywords} = page.frontmatter; // Display flags const isReference = collection === 'reference'; const isReferenceIndex = isCollectionRootPage && isReference; const isPatternsIndex = isCollectionRootPage && collection === 'patterns'; const isExtensionsIndex = isCollectionRootPage && collection === 'extensions'; const isEssaysIndex = isCollectionRootPage && collection === 'essays'; const isDocsRoot = isCollectionRootPage && collection === 'docs'; // Extensions is flat (no subfolders), but sibling navigation is useful, so show sidebar on inner pages. const isFlatCollectionWithSidebar = collection === 'extensions'; const includeSidebar = isDocsRoot || (!!(folder?.folders?.length || (isFlatCollectionWithSidebar && folder?.files?.length)) && !isReferenceIndex && !isPatternsIndex && !isExtensionsIndex); const includeHeader = !isHomePage; const includeMockServer = file?.frontmatter?.includeMockServer === true; const includePagination = !isCollectionRootPage && !isSubfolderIndexPage && !!(file?.prev || file?.next); const useWideLayout = (isCollectionRootPage || isSubfolderIndexPage) && collection === 'about'; let headings: any[] = []; let sidebarFolder = folder!; if (file) { headings = (await render(file)).headings; } else if (isReferenceIndex) { headings = folder!.folders.map(sub => ({ depth: 2, slug: sub.slug, text: sub.frontmatter.title })); } else if (isDocsRoot) { ({headings, sidebar: sidebarFolder} = await buildDocsSidebar(folder)); headings = headings.map(h => h.depth === 2 ? {...h, label: true} : h); } const includeTableOfContents = headings.length > 0; --- {includeSidebar && }
{includeHeader && }
{includeMockServer && } {includePagination && }
{isSubfolderIndexPage && ( )}
{includeTableOfContents && ( )}